process.env.VUE_APP_NAME = require('./package.json').name
process.env.VUE_APP_VERSION = require('./package.json').version
process.env.VUE_APP_CORE_VERSION =
  require('./package.json').dependencies['anov-core']
process.env.VUE_APP_DESCRIPTION = require('./package.json').description
process.env.VUE_APP_PROJECTID = require('./package.json').projectId
process.env.VUE_APP_PROJECTNAME = require('./package.json').projectName
process.env.VUE_APP_COPYRIGHT = require('./package.json').copyright
// process.env.VUE_APP_DIRNAME = __dirname
process.env.VUE_APP_DIRNAME = '' // 项目所在目录
process.env.VUE_APP_PKGINFO = '{}' // 项目开发软硬件配置信息
process.env.VUE_APP_PKGID = '' // 项目软硬件Id
process.env.VUE_APP_LEVEL = require('./package.json').level
process.env.VUE_APP_TIMRESTAMP = +new Date()
const VueFilenameInjector = require('@d2-projects/vue-filename-injector')
const CompressionPlugin = require('compression-webpack-plugin')
const path = require('path')

function resolve(dir) {
  return path.join(__dirname, dir)
}
// const { VUE_APP_API_PROXY = 'http://10.16.3.25:58809/' } = process.env

//如果不走权鉴的话 直接走8530 要记得去掉gw、v2之类的东西
const { VUE_APP_API_PROXY = 'http://10.19.64.69:8530' } = process.env
module.exports = {
  lintOnSave: false,
  publicPath: './',
  productionSourceMap: false,
  chainWebpack: (config) => {
    VueFilenameInjector(config, {
      propName: '__anovFile' // default
    })
  },
  pages: {
    index: {
      entry: 'src/main.js',
      template: 'public/index.html',
      filename: 'index.html',
      title: process.env.VUE_APP_PROJECTNAME,
      description: process.env.VUE_APP_DESCRIPTION,
      copyright: process.env.VUE_APP_COPYRIGHT,
      chunks: ['chunk-vendors', 'chunk-common', 'index']
    }
  },
  devServer: {
    headers: { 'Access-Control-Allow-Origin': '*' },
    watchOptions: {
      ignored: [/public\/img\/preview_\w*\.(jpg|jpeg|png)/]
    },
    compress: true,
    // host: '0.0.0.0',
    proxy: {
      '/cdn/slsw/': {
        target: 'http://10.17.0.228:8099',
        changeOrigin: true
      },
      '/': {
        target: VUE_APP_API_PROXY,
        ws: false,
        pathRewrite: { '/v2': '' }
      }
    }
  },
  configureWebpack: {
    resolve: {
      alias: {
        '@a': resolve('src/assets'),
        '@c': resolve('src/components'),
        '@u': resolve('src/utils'),
        '@p': resolve('src/pages')
      }
    },
    plugins:
      process.env.NODE_ENV === 'production'
        ? [
          new CompressionPlugin({
            filename: '[path].gz[query]',
            // 压缩算法
            algorithm: 'gzip',
            // 匹配文件
            test: /\.js$|\.css$|\.json$|\.ttf$/,
            // 压缩超过此大小的文件,以字节为单位
            threshold: 10240,
            minRatio: 0.8,
            // 删除原始文件只保留压缩后的文件
            deleteOriginalAssets: false
          })
        ]
        : []
  },
  pluginOptions: {
    dll: {
      entry: {
        vueruntime: [
          'vue',
          'vue-router',
          'vuex',
          // 'vue-wait',
          'axios',
          'qs'
          // 'loadsh',
          // 'lodash.merge',
          // 'lodash.mergewith'
        ],
        anovruntime: ['echarts', 'dtc', 'anov-core', 'hotkeys-js', 'jsencrypt']
      },
      open: process.env.NODE_ENV === 'production',
      inject: true
    }
  }
}
